package sevensoft.函数式编程;

import org.junit.Test;
import sevensoft.创建型模式.原型模式.浅克隆.Student;

import java.math.BigDecimal;
import java.util.*;
import java.util.concurrent.ExecutionException;
import java.util.stream.Collectors;

public class App {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        Optional<Object> o = Optional.ofNullable(null);

        List<Student> list = Arrays.asList(
                new Student("zs", 21),
                new Student("ls", 20),
                new Student("ww", 19),
                new Student("zl", 22)
        );

        Integer reduce = list.stream()
                .map(Student::getAge)
                .reduce(Integer.MAX_VALUE, (res, elm) -> {
                    System.err.println(res);
                    System.err.println(elm);
                    return res > elm ? elm : res;
                });

        System.out.println(reduce);

        List<Student> collect = list.stream()
                .sorted((o1, o2) -> o2.getAge() - o1.getAge())
                .skip(0)
                .limit(2)
                .collect(Collectors.toList());
        System.out.println(collect);

        Integer i = list.stream()
                .map(Student::getAge)
                .max((o1, o2) -> o1 - o2)
                .get();
        System.out.println(i);

        boolean b = list.stream()
                .anyMatch(student -> student.getAge() > 30);
        System.out.println(b);

        list.stream()
                .filter(student -> student.getAge() > 20 && !student.getName().substring(1).equals("w"))
                .forEach(System.out::println);
    }

    @Test
    public void test01() {
//        double money=1000;
//        System.out.println(money - 988.99);

        BigDecimal money = new BigDecimal(1000);
        BigDecimal subtract = money.subtract(new BigDecimal("988.99"));

        System.out.println(subtract);
    }


}
